$(function(){
	$('.avatar-box').on('mouseenter', function(){
		$('.avatar-edit').css({display: 'block'});
	}).on('mouseleave', function(){
		$('.avatar-edit').css({display: 'none'});
	});
	$("form").validate({
		rules: {
			nickName: {
				required: true,
				letterAndNumber: true,
				remote: {
                    data:{id:$("#js_id").val()},
					url : '/api/checkNickName',
					dataFilter: function(response){
						var data = JSON.parse(response);
						return data.status == 'ok' ? 'true' : 'false';
					}
				}
			}
		},
		messages: {
			nickName: {
				required: "请输入昵称",
				letterAndNumber: '昵称只能由字母和数字组成',
				remote: "该昵称已占用"
			}
		},
       submitHandler:function(form){
           $.post(form.action,$(form).serialize(),
               function(data,status){
                  if(data.status == 'ok'){
                     $(".alert-success").fadeIn(1000);
                      setTimeout(function(){
                          $(".alert-success").fadeOut(1000);
                      },3000);
                  }else{
                      $(".alert-warning").text(data.message).fadeIn(1000);
                      setTimeout(function(){
                          $(".alert-warning").fadeOut(1000);
                      },3000);
                  }
               });
       }
	});

});